package com.hxkcloud.patient.dborm;

import android.content.Context;

import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.table.TableUtils;
import com.hxkcloud.patient.beans.BasicInfoTimeBean;

import java.sql.SQLException;
import java.util.List;

/**
 * Created by william_sun on 2016-07-26.
 * Description:基础数据更新时间数据库操作类
 */
public class BasicInfoTimeDao {

    private Context context;
    private Dao<BasicInfoTimeBean, Integer> timeDao;

    public BasicInfoTimeDao(Context context) {
        this.context = context;
        try {
            timeDao = DatabaseHelper.getHelper(context).getDao(BasicInfoTimeBean.class);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void setTime(List<BasicInfoTimeBean> times) {
        try {
            clearTime();
            for (BasicInfoTimeBean t : times) {
                timeDao.create(t);
            }
        } catch (SQLException e) {
        }
    }

    public List<BasicInfoTimeBean> getTime() {
        try {
            return timeDao.queryForAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public void clearTime() {
        try {
            TableUtils.clearTable(timeDao.getConnectionSource(), BasicInfoTimeBean.class);
//            addressDao.queryRaw("delete from addressBean");
//            addressDao.queryRaw("update sqlite_sequence SET seq = 0 where name ='addressBean'");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
